﻿//JumbotCms_4.1 Final
using System;
using JumbotCms.Common;

namespace JumbotCms.WebFile.Passport
{
    public partial class _getpassword : JumbotCms.API.UserCenter
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (q("act") != "reset")
            {
                Response.Write(GetPageHtml("passport_getpassword"));
            }
            else
            {
                string RandomCode = GetRandomNumberString(8, false);
                doh.Reset();
                doh.ConditionExpress = "username=@username and email=@email";
                doh.AddConditionParameter("@username", f("txtUserName"));
                doh.AddConditionParameter("@email", f("txtEmail"));
                doh.AddFieldItem("UserPass", GetHash32(RandomCode));
                if (doh.Update("jcms_normal_user") > 0)
                {
                    string _body = "用户您好！<br>" +
                        "您在" + site.Name + "重置了密码，新密码是：" + RandomCode;
                    if (SendMail(f("txtEmail"), site.Name + "密码找回", _body))
                        Response.Write("JumbotCms.Alert('邮件已发送，请立即去查收', '1', \"window.location='http://mail." + f("txtEmail").Split('@')[1].ToLower() + "';\");");
                    else
                        Response.Write("JumbotCms.Alert('邮件发送失败，请稍后再试', '0');");
                }
                else
                    Response.Write("JumbotCms.Alert('信息不匹配', '0');");
            }
        }
    }
}
